package com.zr.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.sql.Insert;
import org.springframework.stereotype.Service;

import com.zr.dao.BaseDao;
import com.zr.dao.OrderDao;
import com.zr.datamodel.GoodTypeDM;
import com.zr.datamodel.OrderDM;
import com.zr.dto.GoodTypeDto;
import com.zr.dto.InsertOrderDto;
import com.zr.dto.OrderDto;
import com.zr.service.OrderService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

@Service("orderService")
public class OrderServiceImpl implements OrderService{
	@Resource
	private BaseDao<OrderDM> baseDao;
	@Resource
	private OrderDao orderDao;
	@Override
	public JSONObject findOrderMsg(int page, int rows,String senderName) {
		// TODO Auto-generated method stub
		JSONObject obj=new JSONObject();
		obj.put("total",orderDao.findOrderCount());
		try {
			List<OrderDM> orders = orderDao.findOrderMsg(page, rows,senderName );
			List<OrderDto> list = new ArrayList<>();
			for (OrderDM order : orders) {
				OrderDto o = new OrderDto();
				o.setEndPlace(order.getEndPlace());
				o.setId(order.getId());
				o.setNumber(order.getNumber());
				o.setReceiverName(order.getReceiverName());
				o.setSenderName(order.getSenderName());
				o.setSenderPhone(order.getSenderPhone());
				o.setSendTime(order.getSendTime());
				o.setStartPlace(order.getStartPlace());
				o.setStatus(order.getStatus().getName());
				list.add(o);
			}
			obj.put("rows", list);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return obj;
	}
	@Override
	public void delOrderMsg(int ids[]) {
		// TODO Auto-generated method stub
		try {
			orderDao.delOrderMsg(0);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Override
	public void insertOrderMsg(OrderDM orders) throws Exception{
		// TODO Auto-generated method stub
//		List<OrderDM> order=orderDao.insertOrderMsg(orders);
//		List<InsertOrderDto> list=new ArrayList<>();
//		for (OrderDM orderDm : order) {
//			InsertOrderDto o=new InsertOrderDto();
//			o.setEndPlace(orderDm.getEndPlace());
//			o.setGoods(orderDm.getGoods());
//			o.setGoodTypeName(orderDm.getOrderType());
//			o.setId(orderDm.getId());
//			o.setNumber(orderDm.getNumber());
//			o.setPayMoney(orderDm.getPayMoney());
//			o.setPayWay(orderDm.getPayWay());
//			o.setReceiverAdress(orderDm.getReceiverAdress());
//			o.setReceiverName(orderDm.getReceiverName());
//			o.setReceiverPhone(orderDm.getReceiverPhone());
//			o.setRemark(o.getRemark());
//			o.setSendData(orderDm.getSendData());
//			o.setSenderAdress(orderDm.getSenderAdress());
//			o.setSenderName(orderDm.getSenderName());
//			o.setSenderPhone(orderDm.getSenderPhone());
//			o.setSendTime(orderDm.getSendTime());
//			o.setStartPlace(orderDm.getStartPlace());
//			o.setStatus(orderDm.getStatus().getName());
//			list.add(o);
//		}
		
	}
	@Override
	public JSONArray findGoodType() {
		// TODO Auto-generated method stub
		return orderDao.findGoodType();
	}
	@Override
	public void updateOrder(OrderDM orderMsg) {
		// TODO Auto-generated method stub
		orderDao.updateOrder(orderMsg);
	}
}
